/**
 * Created by DELL on 2017/6/23.
 */
var houseId=common.getQueryString("houseId");
var recordId=common.getQueryString("recordId");
var $form=$("form");
$form.validate({
    /**
     * ignore：忽略某些元素不验证
     * @type {String}
     * 例如：ignore: ".ignore" ，忽略所有的带ignore class 的标签
     */
    ignore: ".ignore"
});
window.formObject = $form;

var $dataPhotos=$("#data-photo-list");
var $noPassCause=$(".noPassCause");
var $noPassCauseTextArea=$noPassCause.find("textarea");
var $dataAuth=$(".data-isAuth");
var $radios=$dataAuth.find("input[type='radio']");
$.post(window.globalHost+common.houseVisitedInfoPath,{id:recordId}).success(function (data) {
    var detailInfo=common.transformData(data);
    common.initInputByName({id:detailInfo.id,noPassCause:detailInfo.noPassCause});
    common.initDivById({
        contractNo:detailInfo.contractNo,
        houseAddress:detailInfo.houseAddress,
        agentName:detailInfo.agentName,
        mobile:detailInfo.mobile,
        createTime:detailInfo.createTime,
    });
    common.getRadioChecked("verifyStatus",detailInfo.verifyStatus);
    if(detailInfo.verifyStatus!=0){
        $radios.attr("disabled",true);
        $dataAuth.off("click","label");
    }
    detailInfo.verifyStatus=="2"?$noPassCause.show():$noPassCause.hide();
    var photoList=detailInfo.visitPhotos.split(",");
    var subDom=photoList.map(function (ele, idx) {
        return '<li><img src="'+window.fileHost+ele+'" alt=""></li>';
    });
    $dataPhotos.html(subDom);
});
$dataPhotos.off("click","li").on("click","li",function (ev) {
    var $this=$(this);
    var selfSrc=$this.find("img").attr("src");
    var content='<p style="margin:0;line-height: 600px;"><img style="width:100%;vertical-align: middle;" src="'+selfSrc+'" alt=""></p>';
    layer.open({
        type:1,
        title:false,
        shadeClose:true,
        content:content,
        area:['600px','600px']
    });
    ev.stopPropagation();
});
$dataAuth.off("click","label").on("click","label",function () {
    var $this=$(this);
    var selfAuth=$this.attr("for");
    selfAuth==='refuse'?$noPassCause.show() && $noPassCauseTextArea.attr("required","true").val():$noPassCause.hide() && $noPassCauseTextArea.removeAttr("required");
});